package com.ruoyi.web.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Attention;
import com.ruoyi.system.service.IAttentionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 关注管理Controller
 *
 * @author ruoyi
 * @date 2022-07-01
 */
@Api("用户关注管理")
@Controller
@RequestMapping("/system/attention")
public class AttentionController extends BaseController {
    private String prefix = "system/attention";

    @Autowired
    private IAttentionService attentionService;

    //    @RequiresPermissions("system:attention:view")
    @GetMapping()
    public String attention() {
        return prefix + "/attention";
    }

    /**
     * 查询关注管理列表
     */
//    @RequiresPermissions("system:attention:list")
    @ApiOperation("查询关注管理列表")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Attention attention) {
        startPage();
        List<Attention> list = attentionService.selectAttentionList(attention);
        return getDataTable(list);
    }

    /**
     * 导出关注管理列表
     */
//    @RequiresPermissions("system:attention:export")
    @Log(title = "关注管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Attention attention) {
        List<Attention> list = attentionService.selectAttentionList(attention);
        ExcelUtil<Attention> util = new ExcelUtil<Attention>(Attention.class);
        return util.exportExcel(list, "关注管理数据");
    }

    /**
     * 新增关注管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存关注管理
     */
//    @RequiresPermissions("system:attention:add")
    @ApiOperation("新增保存关注管理")
    @Log(title = "关注管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Attention attention) {
        return toAjax(attentionService.insertAttention(attention));
    }

    /**
     * 修改关注管理
     */
//    @RequiresPermissions("system:attention:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Attention attention = attentionService.selectAttentionById(id);
        mmap.put("attention", attention);
        return prefix + "/edit";
    }

    /**
     * 修改保存关注管理
     */
//    @RequiresPermissions("system:attention:edit")
    @ApiOperation("修改保存关注管理")
    @Log(title = "关注管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Attention attention) {
        return toAjax(attentionService.updateAttention(attention));
    }

    /**
     * 删除关注管理
     */
//    @RequiresPermissions("system:attention:remove")
    @ApiOperation("删除关注")
    @Log(title = "关注管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(attentionService.deleteAttentionByIds(ids));
    }

    /**
     * 根据id删除
     *
     * @param id 关注编号
     * @return
     */
    @PostMapping("/myremove")
    @ResponseBody
    public AjaxResult myremove(@RequestParam("id") Long id) {
        return toAjax(attentionService.deleteAttentionById(id));
    }

    /**
     * 添加关注
     *
     * @param attention
     * @return
     */
    @PostMapping("/myadd")
    @ResponseBody
    public AjaxResult myadd(Attention attention) {
        List<Attention> attentions = null;
        attentions = attentionService.selectAttentionList(attention);
        System.out.println(attentions);
        if (attentions.size() == 0) {
            return toAjax(attentionService.insertAttention(attention));
        } else {
            return toAjax(0);
        }
    }

    /**
     *
     * @param userOne 用户关注（关注列表）
     * @return
     */
    @PostMapping("/getlistuserone")
    @ResponseBody
    public AjaxResult getUserOne(Long userOne) {
        Attention attention=new Attention();
        attention.setUseridOne(userOne);
        return success(attentionService.selectAttentionList(attention));
    }
    /**
     *
     * @param userTwo 用户被关注（粉丝列表）
     * @return
     */
    @PostMapping("/getlistusertwo")
    @ResponseBody
    public AjaxResult getUserTwo(Long userTwo) {
        Attention attention=new Attention();
        attention.setUseridTwo(userTwo);
        return success(attentionService.selectAttentionList(attention));
    }

}
